package com.jiot.controller.project;

import com.zg.cloud.BaseResponse;
import com.zg.cloud.annotation.TokenCheck;
import com.zg.cloud.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import req.project.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author liling
 * @date 2020/10/14 19:15
 * @description
 **/
@RestController
@RequestMapping("/device/project")
@Api(value = "项目模块")
public class ProjectController {

    @Resource
    private ProjectService projectService;

    @PostMapping("/app/add")
    @TokenCheck
    @ApiOperation(value = "app用户新增项目", notes = "project")
    public BaseResponse appAdd(@RequestBody @Valid AppAddProjectReq appAddProjectReq) {
        projectService.appAdd(appAddProjectReq);
        return new BaseResponse();
    }

    @PostMapping("/app/remove")
    @TokenCheck
    @ApiOperation(value = "app用户删除项目", notes = "project")
    public BaseResponse appRemove(@RequestBody @Valid AppDeleteProjectReq appDeleteProjectReq) {
        projectService.appRemove(appDeleteProjectReq);
        return new BaseResponse();
    }

    @PostMapping("/app/list")
    @TokenCheck
    @ApiOperation(value = "app用户查询项目列表", notes = "project")
    public BaseResponse appList(@RequestBody @Valid AppGetListReq appGetListReq) {
        return new BaseResponse(projectService.appList(appGetListReq));
    }

    @PostMapping("/app/info")
    @TokenCheck
    @ApiOperation(value = "app用户查询项目详情", notes = "project")
    public BaseResponse appInfo(@RequestBody @Valid AppGetProjectInfoReq appGetProjectInfoReq) {
        return new BaseResponse(projectService.appInfo(appGetProjectInfoReq));
    }

    @PostMapping("/app/reset/name")
    @TokenCheck
    @ApiOperation(value = "app用户修改项目名称", notes = "project")
    public BaseResponse appResetName(@RequestBody @Valid AppResetProjectNameReq appResetProjectNameReq) {
        projectService.appResetName(appResetProjectNameReq);
        return new BaseResponse();
    }

    @PostMapping("/app/reset/address")
    @TokenCheck
    @ApiOperation(value = "app用户修改项目地址", notes = "project")
    public BaseResponse appResetAddress(@RequestBody @Valid AppResetProjectAddressReq appResetProjectAddressReq) {
        projectService.appResetAddress(appResetProjectAddressReq);
        return new BaseResponse();
    }

    @PostMapping("/app/reset/scene")
    @TokenCheck
    @ApiOperation(value = "app用户修改项目场景", notes = "project")
    public BaseResponse appResetScene(@RequestBody @Valid AppResetProjectSceneReq appResetProjectSceneReq) {
        projectService.appResetScene(appResetProjectSceneReq);
        return new BaseResponse();
    }

    @PostMapping("/app/add/scene")
    @TokenCheck
    @ApiOperation(value = "app用户新增项目场景", notes = "project")
    public BaseResponse appAddScene(@RequestBody @Valid AppAddProjectSceneReq appAddProjectSceneReq) {
        return new BaseResponse(projectService.appAddScene(appAddProjectSceneReq));
    }

    @PostMapping("/app/remove/scene")
    @TokenCheck
    @ApiOperation(value = "app用户删除项目场景", notes = "project")
    public BaseResponse appRemoveScene(@RequestBody @Valid AppRemoveProjectSceneReq appRemoveProjectSceneReq) {
        projectService.appRemoveScene(appRemoveProjectSceneReq);
        return new BaseResponse();
    }

    @PostMapping("/app/reset/industry")
    @TokenCheck
    @ApiOperation(value = "app用户修改行业信息", notes = "project")
    public BaseResponse appResetIndustry(@RequestBody @Valid AppResetIndustryReq appResetIndustryReq) {
        projectService.appResetIndustry(appResetIndustryReq);
        return new BaseResponse();
    }

    @PostMapping("/list/by/ids")
    @TokenCheck
    @ApiOperation(value = "批量查询", notes = "project")
    public BaseResponse listByIds(@RequestBody @Valid GetListByIdsReq getListByIdsReq) {
        return new BaseResponse(projectService.listByIds(getListByIdsReq));
    }

    @PostMapping("/project/scene/list")
    @TokenCheck
    @ApiOperation(value = "查询项目场景列表", notes = "project")
    public BaseResponse projectSceneList(@RequestBody @Valid GetSceneListByProjectReq getSceneListByProjectReq) {
        return new BaseResponse(projectService.projectSceneList(getSceneListByProjectReq));
    }

    @PostMapping("/count/project/and/device")
    @TokenCheck
    @ApiOperation(value = "根据用户id查询项目数和设备数", notes = "project")
    public BaseResponse countProjectAndDevice() {
        return new BaseResponse(projectService.countProjectAndDevice());
    }

    @PostMapping("/find/project/and/device/by/user/id")
    @TokenCheck
    @ApiOperation(value = "根据用户id查询项目和设备信息", notes = "project")
    public BaseResponse findProjectAndDeviceByUserId() {
        return new BaseResponse(projectService.findProjectAndDeviceByUserId());
    }

    @PostMapping("/get/project/by/user/id/and/device/status")
    @TokenCheck
    @ApiOperation(value = "根据用户和设备状态查询项目", notes = "project")
    public BaseResponse getProjectByUserIdAndDeviceStatus(@RequestBody @Valid GetProjectByUserIdAndDeviceStatusReq getProjectByUserIdAndDeviceStatusReq) {
        return new BaseResponse(projectService.getProjectByUserIdAndDeviceStatus(getProjectByUserIdAndDeviceStatusReq));
    }
}
